<template>
	<div class="audit-wrapper">
		<div class="head">
			<span class="title">
				{{ $t('funds.fund_audit.rebate_check_detail_title') }}
			</span>
			<div class="right-btn">
				<el-button plain @click="goBack">
					{{ $t('common.back') }}
				</el-button>
			</div>
		</div>
		<div class="audit-content detailBoxStyle flex-row-container">
			<div class="tree-box mr15">
				<CommonProxyTree
					ref="proxyTree"
					:selectedData.sync="selectedData"
					:detailData="detailData"
				/>
			</div>

			<TreeRightDetailComponent
				v-if="selectedData.type === 1"
				:tableLoading="tableLoading"
				:tabTableLoading="tabTableLoading"
				:tabTitle="tabTitle"
				:tabTableList="tabTableList"
				:tabTableColumn="tabTableColumn"
				:dataList="dataList"
				@getTabSelectVal="getTabSelectVal($event)"
			>
				<template v-slot:accountStatus="{ rowData }">
					<span
						v-if="rowData.loginLockStatus === 1"
						class="disableRgba"
					>
						{{ $t('common.login_lock_status') }}
					</span>
					<span
						v-if="rowData.paymentLockStatus === 1"
						class="deleteRgba"
					>
						{{ $t('common.account_lock_status') }}
					</span>
					<span
						v-if="
							rowData.loginLockStatus === 0 &&
								rowData.paymentLockStatus === 0
						"
						class="normalRgba"
					>
						{{ $t('common.account_status_normal') }}
					</span>
				</template>
				<template v-slot:payoutStatus="{ rowData }">
					<span>
						{{
							typeFilter(
								rowData.payoutStatus,
								'proxyPayoutStatus'
							)
						}}
					</span>
				</template>
			</TreeRightDetailComponent>
			<memberRebate
				v-else
				:selectedData="selectedData"
				:row="detailData"
			/>
		</div>
	</div>
</template>

<script>
import list from '@/mixins/list'
import dayjs from 'dayjs'
import CommonProxyTree from '@/components/CommonProxyTree/index'
import memberRebate from './member-rebate'
export default {
	components: {
		CommonProxyTree,
		memberRebate,
		TreeRightDetailComponent: () =>
			import('@/components/TreeRightDetailComponent')
	},
	mixins: [list],
	props: {
		detailData: {
			type: Object,
			required: true
		}
	},
	data() {
		this.loadData = this.throttle(this.loadData, 1000)
		return {
			tableLoading: false,
			selectedData: {
				type: 1,
				userName: ''
			},
			tabTableLoading: false,
			activeTab: '1',
			receiveRebateDate: '',
			dataList: [
				{
					title: this.$t(
						'funds.fund_audit.agent_withdrawal_review_detail_title_2'
					),
					tableDataList: [],
					tableDataColumn: [
						{
							prop: 'userName',
							label: this.$t('funds.proxy_name'),
							minWidth: '80',
							align: 'center',
							showTip: true,
							renderType: 'defautlSolt'
						},
						{
							prop: 'parentProxyName',
							label: this.$t(
								'funds.proxy_member_funds_record.parent_proxy_account'
							),
							minWidth: '80',
							align: 'center',
							showTip: true,
							renderType: 'defautlSolt'
						},
						{
							prop: 'merchantName',
							label: this.$t('common.belong_merchant'),
							minWidth: '90',
							align: 'center',
							showTip: true,
							renderType: 'defautlSolt'
						},
						{
							prop: 'accountStatus',
							label: this.$t(
								'funds.proxy_member_funds_record.account_status'
							),
							minWidth: '100',
							align: 'center',
							showTip: true,
							renderType: 'slot',
							slotName: 'accountStatus'
						},
						{
							prop: 'createdAt',
							label: this.$t('funds.fund_audit.register_time'),
							minWidth: '120',
							align: 'center',
							showTip: true,
							renderType: 'defautlSolt'
						}
					]
				},
				{
					title: '',
					tableDataList: [],
					tableDataColumn: [
						{
							prop: 'proxyName',
							label: this.$t('funds.proxy_name'),
							minWidth: '80',
							align: 'center',
							showTip: true,
							renderType: 'defautlSolt'
						},
						{
							prop: 'payoutStatus',
							label: this.$t('funds.fund_audit.rebate_state'),
							minWidth: '80',
							align: 'center',
							showTip: true,
							renderType: 'slot',
							slotName: 'payoutStatus'
						},
						{
							prop: 'personRebateAmount',
							label: this.$t(
								'funds.proxy_member_funds_record.person_rebate_amount'
							),
							minWidth: '90',
							align: 'center',
							showTip: true,
							renderType: 'amount'
						},
						{
							prop: 'childRebateAmount',
							label: this.$t(
								'funds.proxy_member_funds_record.child_rebate_amount'
							),
							minWidth: '100',
							align: 'center',
							showTip: true,
							renderType: 'amount'
						},
						{
							prop: 'rebateAmount',
							label: this.$t(
								'funds.proxy_member_funds_record.rebate_amount_point'
							),
							minWidth: '120',
							align: 'center',
							showTip: true,
							renderType: 'amount'
						}
					]
				}
			],
			tabTitle: [
				{
					name: '1',
					label: this.$t('funds.fund_audit.team_rebate_detail')
				},
				{
					name: '2',
					label: this.$t('funds.fund_audit.direact_member_detail')
				}
			],
			tabTableList: [],
			tabTableColumn: []
		}
	},
	computed: {},
	watch: {
		selectedData(data) {
			this.paramProxyId = data.id
			if (!this.paramProxyId) {
				this.getproxyRebateDetailList(this.detailData.id)
				this.getTabSelectVal()
			} else {
				this.getProxyNumberInfo(data.userName)
				this.getproxyRebateDetailList(data.id)
				this.getTabSelectVal()
			}
		}
	},
	created() {
		this.dataList[1].title =
			dayjs(this.detailData.cycleName).format('YYYY-MM-DD') +
			'' +
			this.$t('funds.fund_audit.received_rebate_statistics')
		// 获取代理树报错取列表中的代理ID查询
	},
	methods: {
		goBack() {
			this.$emit('goBack')
		},
		// 获取选项卡切换的数据
		getTabSelectVal(data) {
			if (data) {
				this.activeTab = data
			}
			this.tabTableColumn = [
				{
					prop: 'venueName',
					label: this.$t('report.project'),
					minWidth: '180',
					align: 'center',
					showTip: true,
					renderType: 'defautlSolt'
				},
				{
					prop: 'rebateAmount',
					label: this.$t(
						'funds.proxy_member_funds_record.rebate_amount_point'
					),
					minWidth: '180',
					align: 'center',
					showTip: true,
					renderType: 'amount'
				},
				{
					prop: 'rebateRate',
					label: this.$t('funds.fund_audit.team_rebate_proportion'),
					minWidth: '180',
					align: 'center',
					showTip: true,
					renderType: 'percentage'
				},
				{
					prop: 'validBetAmount',
					label: this.$t('funds.fund_audit.team_valid_bet'),
					minWidth: '180',
					align: 'center',
					showTip: true,
					renderType: 'amount'
				}
			]
			this.getTeamRebateDetail()
		},
		// 获取团队返点明细/获取直属会员贡献明细
		getTeamRebateDetail() {
			this.tabTableLoading = true
			const params = {
				reportType: this.activeTab,
				reportDate: dayjs(this.detailData.cycleEndDate).format(
					'YYYYMMDD'
				),
				id: this.paramProxyId
					? this.paramProxyId
					: this.detailData.proxyId
			}
			this.tabTableList = []
			this.$api
				.getTeamRebateDetailApi(params)
				.then((res) => {
					const { code, data } = res
					this.tabTableLoading = false
					if (code === 200) {
						this.tabTableList = data || []
					}
				})
				.catch(() => {
					this.tabTableLoading = false
				})
		},
		// 获取代理账号信息
		getProxyNumberInfo(userName) {
			const params = {
				merchantId: this.detailData.merchantId,
				userName: userName
			}
			this.dataList[0].tableDataList = []
			this.tableLoading = true
			this.$api
				.getProxyAccountInfo(params)
				.then((res) => {
					this.tableLoading = false
					this.dataList[0].tableDataList.push(res.data || {})
				})
				.catch(() => {
					this.tableLoading = false
				})
		},
		// 本期返点明细
		getproxyRebateDetailList(proxyId) {
			this.tableLoading = true
			this.dataList[1].tableDataList = []
			const params = {
				pageNum: this.pageNum,
				pageSize: 10000,
				reportEndDate: dayjs(this.detailData.cycleEndDate).format(
					'YYYYMMDD'
				),
				reportStartDate: dayjs(this.detailData.cycleStartDate).format(
					'YYYYMMDD'
				),
				proxyId: proxyId
			}
			this.$api
				.getProxyRateDetailPageAPI(params)
				.then((res) => {
					const { record } = res.data || {}
					this.tableLoading = false
					this.dataList[1].tableDataList = record || []
				})
				.catch(() => {
					this.tableLoading = false
				})
		}
	}
}
</script>

<style lang="scss" scoped>
.tree-box {
	width: 320px;
	flex-shrink: 0;
	height: auto;
	overflow: auto;
	::v-deep .el-card__body {
		padding-left: 0px;
		width: 100%;
	}
}
::v-deep .el-tabs__item {
	font-size: 16px;
	font-weight: bold;
}
.txtfeed {
	width: 160px;
	table-layout: fixed;
	word-break: break-all;
	overflow: hidden;
}
.audit-wrapper {
	color: #666666;
	margin: 24px 16px 20px 16px;
	.head {
		height: 70px;
		line-height: 70px;
		width: 100%;
		background: #000;
		border-radius: 2px;
		padding: 0 30px;
		.title {
			font-weight: 600;
			color: rgb(192, 190, 190);
		}
		.right-btn {
			float: right;
		}
	}

	.audit-content {
		.block {
			padding: 30px;
			.name {
				font-weight: 600;
				color: #303133;
			}
			.block-content {
				position: relative;
				width: 100%;
				margin-top: 15px;
			}
		}
		.rebate-details {
			padding-bottom: 50px;
			.details-page {
				margin-top: 10px;
				position: absolute;
				right: 0;
			}
		}
	}
}

.count-single-row {
	height: 40px;
	p {
		height: 40px;
		line-height: 40px;
		color: #5c5c5c;
		font-weight: 700;
		span {
			display: inline-block;
			width: 20px;
			height: 20px;
		}
	}
}

.audit-dialog {
	::v-deep .el-dialog__header {
		color: #909399;
		font-weight: 700;
		text-align: left;
	}
}

.active-dialog {
	::v-deep .el-dialog__header {
		padding: 10px 20px 10px;
	}
	::v-deep .el-dialog__body {
		padding: 20px 20px;
	}
	.tabs-wrapper {
		display: flex;
		.tab {
			width: 120px;
			height: 40px;
			line-height: 40px;
			text-align: center;
			border: 1px solid rgba(0, 0, 0, 0.15);
			font-size: 14px;
			font-weight: 600;
			color: #000000a3;
			cursor: pointer;
			margin-right: 20px;
		}
	}
	.active {
		background: #00bfbf;
	}
	.type-name {
		padding: 0 0 20px;
		font-weight: 600;
		.num {
			color: blue;
		}
	}
}
::v-deep .el-table {
	.high-light {
		color: #0dc5e3;
	}
}
.detailBoxStyle {
	border: none !important;
	margin-top: 10px;
	overflow: hidden;
}
</style>
